<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="../lib/layui/css/layui.css">
    <link href="../css/common.less" rel="Stylesheet">
    <script src="../lib/layui/layui.js"></script>
    <script src="../lib/echarts-4.2.1/echarts.js"></script>
    <script src="../lib/echarts-4.2.1/shine.js"></script>
</head>
<body>
<div id="content-pane" class="layui-body" style="left: 0">
    <div id="chart" style="height: 800px;width: 1000px"></div>
    <script>
        layui.use("jquery", function () {
            layui.$(function () {
                let dataArr = [];//每天的份额
                let start = 1;//起始值
                let deltaArr = [];//每天较昨天的涨跌数量
                let xData = [];

                let buyTotal = 0;
                let getTotal = 0;
                for (var i = 0; i < 3650; i++) {
                    let delta = (Math.random() - 0.5) / 10;
                    deltaArr[i] = delta;
                    start = start * (1 + delta);
                    dataArr.push(start);
                    xData.push(i);

                    // if (getTotal > buyTotal * 1.05 && i > 5) {
                    //     console.log("test.html:36->buyTotal", buyTotal);
                    //     console.log("test.html:37->getTotal", getTotal);
                    //     console.log("test.html:37->days", i);
                    //     console.log("test.html:37->rate", getTotal / buyTotal);
                    //     break;
                    // } else {
                    //     getTotal += 1 / start;
                    //     buyTotal += 1;
                    // }
                    getTotal += 1 / start;
                    buyTotal += 1;

                }
                // console.log("test.js:9->start", start);
                // console.log("test.js:10->deltaArr", deltaArr);
                // console.log("test.js:12->dataArr", dataArr);

                console.error("test.html:43->buyTotal", buyTotal);
                console.error("test.html:44->getTotal", getTotal.toFixed(4));
                console.log("test.html:37->rate", getTotal / buyTotal);

                var chart = echarts.init(document.getElementById("chart"));
                chart.setOption({
                    tooltip: {
                        trigger: 'item',
                    },
                    xAxis: {
                        type: 'category',
                        data: xData,
                        axisLabel: {
                            rotate: 0,
                        },
                    },
                    yAxis: {
                        type: 'value',
                        axisLabel: {
                            rotate: 0,
                        },
                    },
                    series: [
                        {
                            data: deltaArr,
                            type: "line"
                        },
                        {
                            data: dataArr,
                            type: "line"
                        },
                    ]
                });
            });
        })

    </script>
</div>
</body>
</html>